package com.energy.analysis.basic.controller;

import com.energy.analysis.basic.entity.PriceData;
import com.energy.analysis.basic.entity.StandData;
import com.energy.analysis.basic.entity.StationData;
import com.energy.analysis.basic.service.PriceService;
import com.energy.analysis.comm.base.BaseController;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@SuppressWarnings("rawtypes")
@RequestMapping(value = "/basic/price")
@Controller
public class PriceController extends BaseController {

    @Autowired
    private PriceService priceService;

  	//价格列表
    @RequiresPermissions("basic_price_list:view")
    @RequestMapping("/list")
    @ResponseBody
    public ModelAndView list(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("price/price");
        PriceData priceData = priceService.getPriceData();
        modelAndView.addObject("priceData", priceData);
        return modelAndView;
    }
    
    //@RequiresPermissions("basic_price_update:view")
    @RequestMapping("/updatePrice")
    @ResponseBody
    public boolean updatePrice(HttpServletRequest request, @RequestParam String id, @RequestParam float ft3qPrice, @RequestParam float jqiPrice, @RequestParam float qqiPrice) {
        PriceData priceData = null;
        if (!StringUtils.isEmpty(id)) {
            priceData = priceService.getPriceById(Integer.parseInt(id));
        }
        if (priceData != null) {
            priceData.setFt3qPrice(ft3qPrice);
            priceData.setJqiPrice(jqiPrice);
            priceData.setQqiPrice(qqiPrice);
            return priceService.updatePriceData(priceData);
        } else {
            priceData = new PriceData();
            priceData.setFt3qPrice(ft3qPrice);
            priceData.setJqiPrice(jqiPrice);
            priceData.setQqiPrice(qqiPrice);
            return priceService.insertPriceData(priceData);
        }
    }

}